﻿using System;
using System.Net;
using System.Text;
using SlideShowDFG2.Properties;

namespace SlideShowDFG2
{
    public class WebClientHelper
    {
        public static WebClient GetNewInstance()
        {
            RegistryHelper registry = new RegistryHelper();

            WebClient client = new WebClient();

            UriBuilder builder = new UriBuilder();
            builder.Scheme = "ftp";
            builder.Host = registry.FtpHost;
            builder.Port = registry.FtpPort;
            builder.Path = registry.FtpSaveDir;
            builder.UserName = registry.FtpUserName;
            builder.Password = registry.FtpPassword;

            NetworkCredential credentials = new NetworkCredential();
            credentials.Password = registry.FtpPassword;
            credentials.UserName = registry.FtpUserName;

            client.BaseAddress = builder.Uri.ToString();
            client.Credentials = credentials;
            client.Encoding = new UTF8Encoding(false, false);

            return client;
        }

        public static int GetFtpResponseCode(WebException exception)
        {
            FtpWebResponse response = (FtpWebResponse)exception.Response;
            return (int)response.StatusCode;
        }
    }
}
